<#include "layout/template.ftl"/>

<@htmlHead title="新增广告">
   	<link rel="stylesheet" href="${resources}/css/fileupload.css" />
</@htmlHead>


<@htmlBody 'page' 'adManage'>

	<!-- breadcrumbs begin -->
	<#include "layout/breadcrumbs.ftl">
	<@breadcrumbs '管理' '新增'></@breadcrumbs>
	<!-- breadcrumbs end -->

	<!-- page-content begin -->
	<div class="page-content">
			
			<!-- page-header begin -->
			<div class="page-header">
					<h1>
						新增
					</h1>
			</div>
			<!-- page-header end -->

			<!-- page-body begin -->
			<div class="row">	
				<div class="col-md-8 col-md-offset-2">
						<input id="uppath" type="hidden" value="${path}/upload/pic">
				
						<!-- 表单开始 -->
						<form class="form-horizontal" id="validation-form" method="post" action="${path}/manage/page/ad/create" >
								
								
								<div class="form-group">
									<label class="control-label col-md-2 no-padding-right" for="cpname">广告标题:</label>
									<div class="col-md-10">
										<div class="clearfix">
											<input type="text" class="form-control" placeholder="请填写广告标题" name="name"   id="name" value="${ad.name}" />
										</div>
									</div>
								</div>
								 	<div class="form-group">
									<label class="control-label col-md-2 no-padding-right" >广告类型:</label>
									<div class="col-md-10">
										<div class="clearfix">
											<select id="type" name="type" style="width: 100%">
												<#list adTypeEnums as enum>
												<option value="${enum.value}">${enum.comment}</option>
												</#list>
											</select>
										</div>
									</div>
								</div>
								
							
								
								
								<div class="form-group">
									<label class="control-label col-md-2 no-padding-right" for="cpname">排序:</label>
									<div class="col-md-10">
										<div class="clearfix">
											<input type="text" class="form-control" placeholder="请输入序号" name="seq"   id="seq" value="${ad.seq}" />
										</div>
									</div>
								</div>
								
						
					  			<input name="picurl" id="picurl" value="${ad.picurl}" type="hidden">
									<div class="form-group">
										<label class="control-label col-md-2 no-padding-right" for="picurl">广告图片:</label>
										<div class="col-md-10">
											<div class="clearfix">
												<div class="settingView">
													<img id="file_0_pic" src="${ad.picurl}"/>
													<input class="picinput" multiple="" type="file" name="file" id="file_0" data-id="file_0" data-img="file_0_pic"  data-txt="file_0_txt" />
												</div>
											</div>
										</div>
									</div>
									
								<div class="form-group" style="color: red;">
									<div class="form-group">
										<label class="control-label col-md-2 no-padding-right" for="picurl"></label>
										  <div class="col-md-10">   
										     广告类型为首页 640*320
										  </div>
									 </div>
								</div>	
								<div class="form-group">
									<label class="control-label col-md-2 no-padding-right" for="cpname">广告链接:</label>
									<div class="col-md-10">
										<div class="clearfix">
											<input type="text" class="form-control" placeholder="请输入广告链接" name="linkurl"   id="linkurl" value="${ad.linkurl}" />
										</div>
									</div>
								</div>	
								
						</form>
						<!-- 表单结束 -->

						<!-- 提交开始 -->
	                    <div class="form-group" style="margin-top: 100px;">
	                    	<div class="col-md-8 center">
		                    	<button id="form-submit" type="button" onclick="mysubmit('validation-form')"  class="btn btn-primary">
									<i class="fa fa-save align-top bigger-125"></i>保存
								</button>
							 
								<button type="reset" class="btn">
									<i class="fa fa-pencil align-top bigger-125"></i>重置
								</button>
							</div>					
                   		</div>
						<!-- 提交结束  -->
				</div>
			</div>
			<!-- page-body end -->
		
	</div>		
	<!-- page-content end -->

</@htmlBody>



<@htmlBodyScript>

	<!-- 富文本编辑器 -->
	<script charset="utf-8" src="${resources}/plugins/kindeditor/4.1.10/kindeditor.js"></script>
	<script charset="utf-8" src="${resources}/plugins/kindeditor/4.1.10/lang/zh_CN.js"></script>
    <!-- 实例化编辑器 -->
    <script type="text/javascript">
		var editor;
	    KindEditor.ready(function(K) {
	            editor = K.create('#content', {
	                    resizeType : 1,
	                    pasteType  : 1,
	                    uploadJson : '${path}/richtext/upload/pic/0/0',
	        		    height : "350px",
	        		    items : ['source', '|',
	                 		    'undo', 'redo', '|', 
	                 		    'cut', 'copy', 'paste','|',
	        		           'justifyleft', 'justifycenter', 'justifyright','justifyfull','|',
	        		           'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',  'superscript','|',
	        		           'image', 'table', 'hr', 'link', 'unlink', '|', 
	        		           'title', 'fontname', 'fontsize', 'forecolor','hilitecolor','|',
	        		           'bold', 'italic', 'underline', 'removeformat', '|', 'about'],
	        		    afterSetData : function(id) {}
	            });
	 	});

    </script>

	<!-- 上传控件 -->
	<script type="text/javascript" src="${resources}/assets/js/ajaxfileupload.js"></script>
	<script src="${resources}/plugins/letsun-upload/upload.js"></script>
	<script>
	    /**
	     * 功能 : 提交表单
		 */
	 	function mysubmit(form){
	 		$("#"+form).submit();
	 	}
		
	</script>

	<!-- 验证框架 -->	
	<script src="${resources}/plugins/jquery-validation/jquery.validate.min.js"></script>
	<script src="${resources}/plugins/jquery-validation/messages_zh.min.js"></script>
	
	<script type="text/javascript">

			jQuery.validator.addMethod("isName", function(value, element) {       
	 			var corpName =  /^[\u0391-\uFFE5\w\-\s\.]{1,50}$/;
  				 return this.optional(element) || corpName.test(value);       
 			}, "请使用汉字、英文字母、数字、下划线、减号、空格或点");   
 			
	
			$('#validation-form').validate({
				errorElement: 'div',
				errorClass: 'help-block',
				focusInvalid: false,
				rules: {
					name: {
						required:true,
						maxlength:30
					},
					seq:{
						required:true,
						range:[1,1000]
					},
					linkurl: {
						required:true,
						url:"请输入正确的链接"
					}
				},
		
				messages: {
				},
		
		
				highlight: function (e) {
					$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
				},
		
				success: function (e) {
					$(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
					$(e).remove();
				},
		
				errorPlacement: function (error, element) {
					if(element.is('input[type=checkbox]') || element.is('input[type=radio]')) {
						var controls = element.closest('div[class*="col-"]');
						if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
						else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
					}
					else if(element.is('.select2')) {
						error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
					}
					else if(element.is('.chosen-select')) {
						error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
					}
					else error.insertAfter(element.parent());
				},
		
				invalidHandler: function (form) {
				}
			});
			
			//上传图片
			$(".picinput").uploadPreview({
				Width: 120,
				Height: 120,
				IsCompression: true,
				Url: "${path}/upload/pic",
				Success: showSuccess,
				Error:showError,
				
			});
			//回调函数
			function showSuccess(id,url){
				$("#"+id).val(url);
				$("#picurl").val(url);
			}
			
			function showError(id,error){
				alert(error);
			}
			
	</script>
</@htmlBodyScript>